﻿//-----------------------------------------------------------------------
// <copyright file="NhRepositoryPersistanceTests.cs" company="OverrideThis">
//     Copyright (c) 2010 OverrideThis.com
// </copyright>
//-----------------------------------------------------------------------
namespace OverrideThis.Core.Tests.Infrastructure.Repository.Impl
{
    using System;
    using System.Linq;
    using NUnit.Framework;
    using OverrideThis.Core.Tests.Infrastructure.Repository.Impl.Domain;

    [TestFixture]
    public class NhRepositoryPersistanceTests : NhRepositoryBaseTestFixture
    {
        [Test]
        public void NhRepositoryCanSaveAndRead()
        {
            // Arrange.
            var name = "John Doe1" + Guid.NewGuid();
            var person1 = new Person { Name = name};
            
            // Act.
            this.Repository.WithTransaction(repo => repo.SaveOrUpdate(person1));

            // Assert.
            this.Repository.Get<Person>().First(p => p.Name == name);
        }

        [Test]
        public void NhRepositoryCanDelete()
        {
            // Arrange.
            var name = "John Doe2" + Guid.NewGuid();
            this.Repository.WithTransaction(repo => repo.SaveOrUpdate(new Person { Name = name}));
            var person = this.Repository.Get<Person>()
                .First(p => p.Name == name);

            // Act.
            this.Repository.WithTransaction(repo => repo.Delete(person));

            // Assert.
            Assert.AreEqual(0, this.Repository.Get<Person>().Count(p => p.Name == name));
        }
    }
}
